#!/usr/bin/python
import sqlite3
import os
import copy

#check for events to send

conn = sqlite3.connect('/var/mobile/dmassms.db')

c = conn.cursor()

c.execute("select * from sendnowmobiles;")

sendlist = []
for row in c:
	sendlist.append(copy.deepcopy(row))

for row in sendlist:
	command = "smssend " + row[6] + " \"(massms) " + row[3].replace("\\","\\\\").replace("\"","\\\"") + "\""
	print(command)
	os.system(command)
	c.execute("insert into sent(alertid,numberid,senttime) select " + str(row[0]) + "," + str(row[5]) + ",datetime('now','localtime');")

conn.commit()
	

	
	
	



